<?php


require(ROOT_PATH. '/includes/lib.common.php');
require(ROOT_PATH. '/includes/lib.time.php');
//require(ROOT_PATH. '/includes/lib.insert.php');
require(ROOT_PATH. '/includes/cls.message.php');
require(ROOT_PATH. '/includes/cls.session.php');
require(ROOT_PATH. '/includes/inc.constant.php');
require(ROOT_PATH. '/conf/app.config.php');

@ini_set('memory_limit',          '16M');
@ini_set('display_errors',        1);
@ini_set('magic_quotes_runtime',  0);
@ini_set('date.timezone',         'PRC');

if (!defined('CURRENCY'))
{
    define('CURRENCY', 'CNY');
}

define('CHARSET', substr(LANG, strpos(LANG, '-') + 1));

//$GLOBALS['service'] = appService::loadService('http');
define('IS_AJAX', (!empty($_SERVER['HTTP_AJAX_REQUEST'])) || (!empty($_REQUEST['ajax'])));

define('DEBUG_MODE', 2); //现网屏蔽错误显示
if (defined('DEBUG_MODE') == false)
{
    define('DEBUG_MODE', 1);
}
elseif ((DEBUG_MODE & 1) == 1)
{
    error_reporting(E_ALL);
}
else
{
	error_reporting(0);
}
//error_reporting(E_ALL);
//set_error_handler('exception_handler');

if (!get_magic_quotes_gpc())
{
    if (!empty($_GET))
    {
        $_GET  = addslashes_deep($_GET);
    }
    if (!empty($_POST))
    {
        $_POST = addslashes_deep($_POST);
    }

    $_COOKIE   = addslashes_deep($_COOKIE);
    $_REQUEST  = addslashes_deep($_REQUEST);
}

if (isset($_GET['arg']))
{
    $tmp = explode(chr(8), base64_decode(str_replace(array('.', '-'), array('+', '/'), $_GET['arg'])));
    $arr = addslashes_deep($tmp);

    foreach ($arr AS $key=>$val)
    {
        $tmp = explode(chr(9), $val);
        if (!isset($_GET[$tmp[0]]))
        {
            $_GET[$tmp[0]] = $tmp[1];
            $_REQUEST[$tmp[0]] = $tmp[1];
        }
    }
    unset($_GET['arg'], $arr, $tmp);
}

//new sqlin();


if (IS_AJAX && strcasecmp(CHARSET, 'utf-8'))
{
    $_POST = ecm_iconv_deep('UTF8', CHARSET, $_POST);
    $_GET = ecm_iconv_deep('UTF8', CHARSET, $_GET);
}

$session_id = $_GET['sessid'];
$GLOBALS['sess'] = new SessionProcessor($GLOBALS['db'], '`ecm_sessions`', '`ecm_sessions_data`', 'ECM_ID', $session_id);
//$GLOBALS['sess']->add_related_table('`ecm_cart`', 'c', 'session_id');

define('SESS_ID', $GLOBALS['sess']->get_session_id());
$GLOBALS['sess']->my_session_start();

